home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / jscriptapplet / src / jscriptapplet.java
Encoding:
Java Source  |  2000-06-23  |  2.5 KB  |  118 lines

  1. /*
  2.  * QuickTime for Java SDK Sample Code
  3.  
  4.    Usage subject to restrictions in SDK License Agreement
  5.  * Copyright: © 1996-1999 Apple Computer, Inc.
  6.  
  7.  */
  8. import java.applet.*;
  9. import java.awt.*;
  10.  
  11. import quicktime.*;
  12. import quicktime.app.*;
  13. import quicktime.io.*;
  14. import quicktime.std.movies.*;
  15. import quicktime.app.players.*;
  16. import quicktime.app.display.*;
  17.  
  18. public class JScriptApplet extends Applet {
  19.     private QTCanvas myCanvas;
  20.     private MoviePlayer myPlayer;
  21.  
  22.     public void init() {
  23.         try    {
  24.         // IMPORTANT, You should not call QTSession.open
  25.         //  multiple times, otherwise you you will need to call QTSession.close the same
  26.         //  number of times to properly shutdown. There appears to be a side effect in Windows 95/98
  27.         //  With the Netscape browser and sun Java plugin where
  28.         //  the Init method could get called Multiple times
  29.         //  Checking the session to see if it is already initialised is tbe correct
  30.         //  method safeguard against this.
  31.             if (QTSession.isInitialized() == false)
  32.             {
  33.                 QTSession.open();
  34.             }
  35.         }
  36.         catch (Exception e)    {
  37.             e.printStackTrace();
  38.             QTSession.close();
  39.         }
  40.     }
  41.     
  42.     public void start () {
  43.         try    {
  44.             myCanvas = new QTCanvas(QTCanvas.kInitialSize, 0.5F, 0.5F);
  45.             add("Center", myCanvas);
  46.             QTFile qtf = new QTFile(getCodeBase().getFile() + getParameter("file"));
  47.             OpenMovieFile movieFile = OpenMovieFile.asRead (qtf);
  48.             Movie myMovie = Movie.fromFile(movieFile);
  49.             myPlayer = new MoviePlayer(myMovie);
  50.  
  51.             myCanvas.setClient(myPlayer, true);
  52.         }
  53.         catch (Exception e)    {
  54.             e.printStackTrace();
  55.             QTSession.close();
  56.         }
  57.     }
  58.     
  59.     public void stop ()    {
  60.         myCanvas.removeClient();
  61.     }
  62.     
  63.     public void destroy () {
  64.         QTSession.close();
  65.     }
  66.     
  67.     public void resetTime (int time) {
  68.         try    {
  69.             myPlayer.setRate(0);
  70.             myPlayer.setTime(time);
  71.         }
  72.         catch (Exception e)    {
  73.             e.printStackTrace();
  74.         }
  75.     }
  76.     
  77.     public void pause () {
  78.         try    {
  79.             if (myPlayer.getRate() == 0)
  80.                 myPlayer.setRate(1);
  81.             else
  82.                 myPlayer.setRate(0);
  83.         }
  84.         catch (Exception e)    {
  85.             e.printStackTrace();
  86.         }
  87.     }
  88.     
  89.     public boolean isPlaying ()    {
  90.         try    {
  91.             return myPlayer.getRate() != 0;
  92.         }
  93.         catch (Exception e)    {
  94.             e.printStackTrace();
  95.         }
  96.         return false;
  97.     }
  98.     
  99.     public int getMaxTime () {
  100.         try    {
  101.             return myPlayer.getDuration();
  102.         }
  103.         catch (Exception e) {
  104.             e.printStackTrace();
  105.         }
  106.         return 0;
  107.     }
  108.     
  109.     public int getMovieTime () {
  110.         try    {
  111.             return myPlayer.getTime();
  112.         }
  113.         catch (Exception e)    {
  114.             e.printStackTrace();
  115.         }
  116.         return 0;
  117.     }
  118. }